1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.48">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000; min-height: 12.0px}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0000bf}
20 span
.s1
{color: #0000bf}
21 span
.s2
{color: #0000bf}
22 span
.s3
{color: #007300}
23 span
.s4
{color: #000000}
24 span
.s5
{font: 10.0px Monaco
}
25 span
.s6
{color: #606060}
26 span
.s7
{font: 12.0px Helvetica
}
27 span
.Apple-tab-span
{white-space:pre
}
31 <p class=
"p1"><b>Language control methods
</b></p>
32 <p class=
"p2"><br></p>
33 <p class=
"p3">Some patterns mimic language-style control methods: conditionals (
<a href=
"../Patterns/Pif.html"><span class=
"s1">Pif
</span></a>), loops (
<a href=
"../Patterns/Pwhile.html"><span class=
"s1">Pwhile
</span></a>) and error cleanup (
<a href=
"../Patterns/Pprotect.html"><span class=
"s1">Pprotect
</span></a>).
</p>
34 <p class=
"p2"><br></p>
36 <li style=
"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><b>Pif(condition, iftrue, iffalse, default):
</b> Evaluates a pattern 'condition' that returns true or false. Then, one value is taken from the true or false branch before going back to evaluate the condition again. The 'default' value or pattern comes into play when the true or false branch stops producing values (returns nil). If the default is not given, Pif returns control to the parent upon nil from either branch.
</li>
38 <p class=
"p2"><br></p>
39 <p class=
"p4">p =
<span class=
"s2">Pbind
</span>(
</p>
40 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\degree
</span>,
<span class=
"s2">Pwhite
</span>(
0,
11,
<span class=
"s2">inf
</span>),
</p>
41 <p class=
"p5"><span class=
"s4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// odd numbered scale degrees get a shorter rhythmic value
</p>
42 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
<span class=
"s2">Pif
</span>(
<span class=
"s2">Pkey
</span>(
<span class=
"s3">\degree
</span>).odd,
0.25,
0.5)
</p>
43 <p class=
"p4">).play;
</p>
44 <p class=
"p6"><br></p>
45 <p class=
"p4">p.stop;
</p>
46 <p class=
"p2"><br></p>
47 <p class=
"p2"><br></p>
49 <li style=
"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><b>Pseed(randSeed, pattern):
</b> Random number generators depend on seed values; setting a specific seed produces a repeatable stream of pseudorandom numbers.
<a href=
"../Patterns/Pseed.html"><span class=
"s1">Pseed
</span></a> sets the random seed before embedding 'pattern', effectively restarting the random number generator at the start of the pattern.
</li>
51 <p class=
"p2"><br></p>
52 <p class=
"p4">p =
<span class=
"s2">Pbind
</span>(
</p>
53 <p class=
"p5"><span class=
"s4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// the random seed is generated once, when creating the Pattern object
</p>
54 <p class=
"p5"><span class=
"s4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// so the same random seed is used every time whenever this pattern object plays
</p>
55 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\degree
</span>,
<span class=
"s2">Pseed
</span>(
0x7FFFFFFF.rand,
<span class=
"s2">Pseries
</span>({ rrand(-
7,
0) },
<span class=
"s2">Pwhite
</span>(
1,
3,
<span class=
"s2">inf
</span>), { rrand(
4,
10) })),
</p>
56 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
0.25</p>
58 <p class=
"p6"><br></p>
59 <p class=
"p7"><span class=
"s4">q = p.play;
<span class=
"Apple-tab-span"> </span></span>// uses one seed
</p>
60 <p class=
"p8">q.stop;
</p>
61 <p class=
"p9"><br></p>
62 <p class=
"p7"><span class=
"s4">r = p.play;
<span class=
"Apple-tab-span"> </span></span>// uses the same seed
</p>
63 <p class=
"p8">r.stop;
</p>
64 <p class=
"p9"><br></p>
65 <p class=
"p7">// reexecute the p = Pbind... and the seed will be different
</p>
66 <p class=
"p6"><br></p>
67 <p class=
"p2"><br></p>
69 <li style=
"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><b>Pprotect(pattern, func):
</b> Like the 'protect' error handling method, if an error occurs while getting the next value from the pattern, the function will be evaluated before the error interrupts execution.
</li>
70 <li style=
"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><b>Ptrace(pattern, key, printStream, prefix):
</b> For debugging, Ptrace prints every return value. Is your pattern really doing what you think? This will tell you. A Ptrace is created automatically by the 'trace' message:
<span class=
"s5">aPattern.trace(key, printStream, prefix)
</span> --
> <span class=
"s5">Ptrace(aPattern, key, printStream, prefix)
</span>.
</li>
71 <li style=
"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><b>Pwhile(func, pattern):
</b> Like while: as long as the function evaluates to true, the pattern is embedded. The function is checked once at the beginning and thereafter when the pattern comes to an end. If it's applied to an infinite pattern, there's no looping because the pattern never gives control back.
</li>
73 <p class=
"p2"><br></p>
74 <p class=
"p5">// Pwhile and Ptrace
</p>
76 <p class=
"p4">~go =
<span class=
"s2">true
</span>;
</p>
77 <p class=
"p4">p =
<span class=
"s2">Pwhile
</span>({ ~go },
<span class=
"s2">Pbind
</span>(
</p>
78 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\degree
</span>,
<span class=
"s2">Pseries
</span>({ rrand(-
7,
0) },
<span class=
"s2">Pwhite
</span>(
1,
3,
<span class=
"s2">inf
</span>), { rrand(
4,
10) })
</p>
79 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.trace(prefix:
<span class=
"s6">"degree: "</span>),
</p>
80 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
0.25</p>
81 <p class=
"p4">)).play;
</p>
83 <p class=
"p6"><br></p>
84 <p class=
"p5"><span class=
"s4">~go =
</span><span class=
"s2">false
</span><span class=
"s4">;
<span class=
"Apple-tab-span"> </span></span>// will stop the whole pattern when the Pbind comes to an end
</p>
85 <p class=
"p6"><br></p>
86 <p class=
"p6"><br></p>
87 <p class=
"p10"><span class=
"s4">Previous:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><a href=
"PG_06d_Parallel_Patterns.html"><span class=
"s7">PG_06d_Parallel_Patterns
</span></a></span></p>
88 <p class=
"p10"><span class=
"s4">Next:
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><a href=
"PG_06f_Server_Control.html"><span class=
"s7">PG_06f_Server_Control
</span></a></span></p>